package com.project.xsf.controller;

import com.alibaba.fastjson.JSONObject;
import com.project.common.entity.PageVo;
import com.project.xsf.entity.MDesignProcedureDetails;
import com.project.xsf.entity.MDesignProcedureModule;
import com.project.xsf.service.MDesignProcedureModuleService;
import com.project.xy.entity.DModuleDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/mDesignProcedureModule")
public class MDesignProcedureModuleController {
    @Autowired
    private MDesignProcedureModuleService mDesignProcedureModuleService ;

    @ResponseBody
    @PostMapping("/addMDesignProcedureModule.action")
    public void addMDesignProcedureModule(String dModuleDetailsArrays,String mDesignProcedureModuleArrays,String mDesignProcedureDetailStr,Integer mDesignProcedureDetailId){
//        System.out.println(dModuleDetailsArrays);
        //将json字符串转换为数组对象
        DModuleDetails[] dModuleDetails= JSONObject.parseObject(dModuleDetailsArrays,DModuleDetails[].class);
        MDesignProcedureModule[] mDesignProcedureModules= JSONObject.parseObject(mDesignProcedureModuleArrays,MDesignProcedureModule[].class);
        MDesignProcedureDetails mDesignProcedureDetails = JSONObject.parseObject(mDesignProcedureDetailStr, MDesignProcedureDetails.class);
        mDesignProcedureDetails.setId(mDesignProcedureDetailId);
//        System.out.println(mDesignProcedureDetails);
        mDesignProcedureModuleService.addMDesignProcedureModule(mDesignProcedureModules,dModuleDetails,mDesignProcedureDetails,mDesignProcedureDetailId);

    }
    @ResponseBody
    @PostMapping("/queryMDesignProcedureModuleByPId.action")
    public List<MDesignProcedureModule> queryMDesignProcedureModuleByPId(Integer pId){
        List<MDesignProcedureModule> mDesignProcedureModules = mDesignProcedureModuleService.queryMDesignProcedureModuleByPId(pId);
//        System.out.println(mDesignProcedureModules);
        return mDesignProcedureModules;
    }
    @ResponseBody
    @PostMapping("/queryMDesignProcedureModuleByPId1.action")
    public PageVo<MDesignProcedureModule> queryMDesignProcedureModuleByPId(@RequestBody Map<String,String> map){
//        System.out.println(map);
        PageVo<MDesignProcedureModule> pageVo = mDesignProcedureModuleService.queryMDesignProcedureModuleByPId(map);

//        System.out.println(mDesignProcedureModules);
        return pageVo;
    }

}
